/*
 * SPDX-License-Identifier: Apache-2.0
 * Copyright Blazebit
 */

package com.blazebit.persistence.testsuite.entity;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import java.io.Serializable;

/**
 *
 * @author Moritz Becker
 * @since 1.2.0
 */
@Entity
@Table(name = "pers_coll")
public class PersonForEntityKeyMaps implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;
    private String name;
    private DocumentForEntityKeyMaps someDocument;

    public PersonForEntityKeyMaps() {
    }

    public PersonForEntityKeyMaps(String name) {
        this.name = name;
    }

    @Id
    @GeneratedValue
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "some_document_id")
    public DocumentForEntityKeyMaps getSomeDocument() {
        return someDocument;
    }

    public void setSomeDocument(DocumentForEntityKeyMaps someDocument) {
        this.someDocument = someDocument;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        PersonForEntityKeyMaps other = (PersonForEntityKeyMaps) obj;
        if (id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!id.equals(other.id)) {
            return false;
        }
        return true;
    }
}
